package com.totem.startup;

import com.totem.base.enums.SubscribeNameEnum;
import com.totem.customer.vo.SubscribeIncentiveVO;
import com.totem.customer.vo.TeamIncentiveVO;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class InitialGlobalConfig {
    public static final Map<Integer, BigDecimal> INVITE_AWARD_RULE = new HashMap<>();
    public static final Map<Integer, TeamIncentiveVO> TEAM_MOTIVATION_RULE = new HashMap<>();
    public static final Map<String, SubscribeIncentiveVO> SPEC_SUBSCRIBE_RULE = new HashMap<>();

    private Boolean subscribeShowSpecial;
    private BigDecimal fundReturnRate;
    private BigDecimal fundWithdrawFee;
    private String withdrawMin;
    private String withdrawMax;
    private BigDecimal withdrawFee;
    private String usdtCollectionAddr;
    private String chargePrivateKey;
    private String chargeAddress;
    private BigDecimal balanceConversionFee;

    static {
        INVITE_AWARD_RULE.put(0, new BigDecimal("0.35"));
        INVITE_AWARD_RULE.put(1, new BigDecimal("0.1"));
        INVITE_AWARD_RULE.put(2, new BigDecimal("0.01"));
        INVITE_AWARD_RULE.put(3, new BigDecimal("0.01"));
        INVITE_AWARD_RULE.put(4, new BigDecimal("0.01"));
        INVITE_AWARD_RULE.put(5, new BigDecimal("0.01"));
        INVITE_AWARD_RULE.put(6, new BigDecimal("0.01"));
        INVITE_AWARD_RULE.put(7, new BigDecimal("0.01"));
        INVITE_AWARD_RULE.put(8, new BigDecimal("0.01"));
        INVITE_AWARD_RULE.put(9, new BigDecimal("0.01"));

        TEAM_MOTIVATION_RULE.put(1, new TeamIncentiveVO(1, new BigDecimal("100"), 0, 5, new BigDecimal("20000"), new BigDecimal("0.1")));
        TEAM_MOTIVATION_RULE.put(2, new TeamIncentiveVO(2, new BigDecimal("100"), 1, 2, new BigDecimal("50000"), new BigDecimal("0.2")));
        TEAM_MOTIVATION_RULE.put(3, new TeamIncentiveVO(3, new BigDecimal("100"), 2, 2, new BigDecimal("150000"), new BigDecimal("0.25")));
        TEAM_MOTIVATION_RULE.put(4, new TeamIncentiveVO(4, new BigDecimal("100"), 3, 2, new BigDecimal("500000"), new BigDecimal("0.3")));
        TEAM_MOTIVATION_RULE.put(5, new TeamIncentiveVO(5, new BigDecimal("100"), 4, 2, new BigDecimal("1000000"), new BigDecimal("0.35")));
        TEAM_MOTIVATION_RULE.put(6, new TeamIncentiveVO(6, new BigDecimal("100"), 5, 2, new BigDecimal("2000000"), new BigDecimal("0.4")));

        SPEC_SUBSCRIBE_RULE.put(SubscribeNameEnum.SUBSCRIBE_DALENT.getCode(), new SubscribeIncentiveVO(SubscribeNameEnum.SUBSCRIBE_DALENT.getCode(), 2, new BigDecimal("0.012"), new BigDecimal("0.15")));
        SPEC_SUBSCRIBE_RULE.put(SubscribeNameEnum.SUBSCRIBE_KING.getCode(), new SubscribeIncentiveVO(SubscribeNameEnum.SUBSCRIBE_KING.getCode(), 3, new BigDecimal("0.012"), new BigDecimal("0.15")));
        SPEC_SUBSCRIBE_RULE.put(SubscribeNameEnum.SUBSCRIBE_SUPREME.getCode(), new SubscribeIncentiveVO(SubscribeNameEnum.SUBSCRIBE_SUPREME.getCode(), 4, new BigDecimal("0.012"), new BigDecimal("0.15")));
    }

    private InitialGlobalConfig(){}

    public void init(Boolean subscribeShowSpecial,
                     BigDecimal fundReturnRate, BigDecimal fundWithdrawFee,
                     String withdrawMin, String withdrawMax, BigDecimal withdrawFee,
                     String usdtCollectionAddr,
                     String chargePrivateKey, String chargeAddress,
                     BigDecimal balanceConversionFee) {
        this.subscribeShowSpecial = subscribeShowSpecial;
        this.fundReturnRate = fundReturnRate;
        this.fundWithdrawFee = fundWithdrawFee;
        this.withdrawMin = withdrawMin;
        this.withdrawMax = withdrawMax;
        this.withdrawFee = withdrawFee;
        this.usdtCollectionAddr = usdtCollectionAddr;
        this.chargePrivateKey = chargePrivateKey;
        this.chargeAddress = chargeAddress;
        this.balanceConversionFee = balanceConversionFee;
    }

    private static class InstanceHolder {
        private static final InitialGlobalConfig INSTANCE = new InitialGlobalConfig();
    }

    public static InitialGlobalConfig instance() {
        return InstanceHolder.INSTANCE;
    }
}
